package org.fatmansoft.teach.models;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.persistence.*;
import javax.validation.constraints.Size;
import java.util.Set;

/**
 * StudentHonor 学生荣誉表实体类 保存学生荣誉的信息，
 * Integer studentHonorId 用户表 studentHonor 主键 student_honor_id
 * Student student 关联到该荣誉所用的Student对象，荣誉所对应的学生信息 student_id 关联 student 表主键 student_id
 * Student student 获奖学生
 * String title 荣誉称号
 * String date 获奖时间
 * String reward 奖赏
 * String level 获奖级别（国家级 省级 校级等）
 *
 */
@Entity
@Data
@EqualsAndHashCode(exclude = {"students"})//添加equals和hashcode的重写，排除students字段
@Table(	name = "student_honor",
        uniqueConstraints = {
        })
public class StudentHonor {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Integer studentHonorId;

        @Size(max = 20)
        private String title;

        @Size(max = 30)
        private String reward;

        @Size(max = 10)
        private String level;

        @Size(max = 20)
        private String date;

        @ManyToMany(mappedBy = "studentHonors", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
        @ToString.Exclude//To string方法中排除student字段
        private Set<Student> students;
}
